package day19.edu;

import org.junit.Test;

import java.util.Arrays;
import java.util.Comparator;

// Created: 19/09/2025, ChangJiang Ru
public class ComparatorTest {
    @Test
    public void test1()
    {
        String[] arr = new String[]{"Tom", "Jerry", "Lucy", "Rose", "Jack"};
        Arrays.sort(arr, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                if(o1 instanceof String && o2 instanceof String)
                {
                    String s1 = (String)o1;
                    String s2 = (String)o2;

                    return s1.compareTo(s2);
                }
                throw new RuntimeException("Type is error");
            }
        });
        for (int i = 0; i < arr.length; i++)
        {
            System.out.println(arr[i]);
        }
    }
}
